home *** CD-ROM | disk | FTP | other *** search
- unit AXTools;
-
- interface
-
- uses
- AXCtrls, ActiveX;
-
- type
- {This class is defined to allow insertion and deletion of the required
- registry settings to signify that this control is "marked as safe"
- for scripting and control initialization. For more info, see MS's
- ActiveX SDK - in the "Security API" section. See TActiveFormControlFactory
- implementation for another example of overriding control factory creation.
- (In Delphi 3.0 and 3.01. 3.02 changed inheritance to expose UpdateRegistry
- as a virtual method of TComObjectFactory instead, so TActiveXControlFactory
- implements an overridden UpdateRegistry that you can browse).
- Also see the unit ObjSafe.pas for the implementation of IObjectSafety}
- TActiveXSafeFactory = class(TActiveXControlFactory)
- procedure UpdateRegistry(Register : boolean); override;
- end;
-
- {Helper functions - see ActiveX SDK for more information}
- function CreateComponentCategory(catid : TIID; catDescription : PWideChar) : HRESULT;
- function RegisterCLSIDInCategory(clsid : TGUID; catid : TGUID) : HRESULT;
- function UnRegisterCLSIDInCategory(clsid : TGUID; catid : TGUID) : HRESULT;
-
- implementation
-
- uses
- ComObj, ObjSafe;
-
- const
- // GUIDs defined in comcat.h section (RTL\WIN\ActiveX)
- IID_IEnumGUID : TGUID = '{0002E000-0000-0000-C000-000000000046}';
- IID_IEnumCategoryInfo : TGUID = '{0002E011-0000-0000-C000-000000000046}';
- IID_ICatRegister: TGUID= '{0002E012-0000-0000-C000-000000000046}';
- IID_ICatInformation: TGUID = '{0002E013-0000-0000-C000-000000000046}';
-
- procedure TActiveXSafeFactory.UpdateRegistry(Register: Boolean);
- begin
- inherited UpdateRegistry(Register);
- if Register then begin
- // Fix for 3.02 patch, which started quoting the location of the OCX. This causes problems.
- CreateRegKey('CLSID\'+GUIDToString(ClassID)+'\'+ComServer.ServerKey, '', ComServer.ServerFileName);
- CreateComponentCategory(CATID_SafeForScripting, 'Controls that are safely scriptable');
- CreateComponentCategory(CATID_SafeForInitializing, 'Controls safely initializable from persistent data');
- RegisterCLSIDInCategory(ClassID, CATID_SafeForScripting);
- RegisterCLSIDInCategory(ClassID, CATID_SafeForInitializing);
- end else begin
- UnRegisterCLSIDInCategory(ClassID, CATID_SafeForScripting);
- UnRegisterCLSIDInCategory(ClassID, CATID_SafeForInitializing);
- end;
- end;
-
- function CreateComponentCategory(catid : TGUID; catDescription : PWideChar) : HRESULT;
- const
- MAX_LEN = 127;
- var
- pcr : ICatRegister;
- catinfo : PCATEGORYINFO;
- len : integer;
- s : string;
- begin
- Result:=CoCreateInstance(CLSID_StdComponentCategoryMgr, nil, CLSCTX_INPROC_SERVER,
- IID_ICatRegister, pcr);
- OleCheck(Result);
-
- // Make sure the HKCR\Component Categories\{..catid...} key is registered
- New(catinfo);
- try
- catinfo^.catid := catid;
- catinfo^.lcid := $0409; // english
-
- // Make sure the provided description is not too long.
- // Only copy the first 127 characters if it is
- s:=WideCharToString(catDescription);
- len := length(s);
- if len>MAX_LEN then
- SetLength(S, MAX_LEN);
- StringToWideChar(s, catinfo^.szDescription, len+1); // Need room for NULL character too
-
- Result := pcr.RegisterCategories(1, catinfo);
- finally
- Dispose(catinfo);
- end;
- end;
-
- function RegisterCLSIDInCategory(clsid : TGUID; catid : TGUID) : HRESULT;
- var
- pcr : ICatRegister;
- rgcatid : array[0..1] of TGUID;
- begin
- Result := CoCreateInstance(CLSID_StdComponentCategoryMgr, nil, CLSCTX_INPROC_SERVER,
- IID_ICatRegister, pcr);
- OleCheck(Result);
-
- // Register this category as being "implemented" by the class.
- rgcatid[0] := catid;
- Result := pcr.RegisterClassImplCategories(clsid, 1, @rgcatid);
- end;
-
- function UnRegisterCLSIDInCategory(clsid : TGUID; catid : TGUID) : HRESULT;
- var
- pcr : ICatRegister;
- rgcatid : array[0..1] of TGUID;
- begin
- Result := CoCreateInstance(CLSID_StdComponentCategoryMgr, nil, CLSCTX_INPROC_SERVER,
- IID_ICatRegister, pcr);
- OleCheck(Result);
-
- // Unregister this category as being "implemented" by the class.
- rgcatid[0] := catid;
- Result := pcr.UnRegisterClassImplCategories(clsid, 1, @rgcatid);
- end;
-
- end.
-